home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2
- Subject: Re: Hungarian notation - whoops!
- Date: 5 Mar 1996 07:23:23 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4hhm9bINNqa3@keats.ugrad.cs.ubc.ca>
- References: <30C40F77.53B5@swsbbs.com> <4h6hlo$hqu@goanna.cs.rmit.EDU.AU> <4h7vgdINNmsh@anvil.ugrad.cs.ubc.ca> <4hgd11$4p4@goanna.cs.rmit.EDU.AU>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4hgd11$4p4@goanna.cs.rmit.EDU.AU>,
- Richard A. O'Keefe <ok@goanna.cs.rmit.EDU.AU> wrote:
- >In all this disucssion I have not once stated or implied that >>C<< is bad.
- >I have been complaining about TWOS COMPLEMENT ARITHMETIC, which is in no
- >way synonymous with C.
- >
- >For another example of the peculiarities of twos complement arithmetic,
- >consider the fact that an arithmetic right shift on a ones complement or
- >sign and magnitude machine is always equivalent to division by a power
- >of 2, but not in a twos complement machine. (I note that the C standard
- >does not guarantee that there will be an arithmetic right shift, so please
- >don't mistake this for a C criticism.)
-
- Okay, I think I have your point of view disilled into a clear form now after
- back and forth revisions and clarifications.
-
- So what are we to do? It is true that: some operations cannot be expressed in
- the ``obvious way'' on two's complement arithmetic. However, it is also true
- that some operations that are expressed in the ``obvious way'' under two's
- complement _fail_ under a sign and magnitude machines!
-
- The road goes both ways. Shall I give an example?
-
- Under two's complement, I can convert a signed quantity into an unsigned
- quantity such that the unsigned is _congruent_ to the signed, modulo a power of
- two. I can do this just by chopping bits (if the unsigned quantity is as
- narrow, or narrower than the signed type being converted). This is how standard
- C defines the operation of converting a signed integral type into an unsigned
- quantity that is narrower (K&R6.1, I think).
-
- You can't do this under sign and magnitude representation. Elsewhere in this
- newsgroup (comp.lang.c) someone criticized me for not using a cast from integer
- to unsigned short to obtain the lower CHAR_BITS of the integer value. I replied
- that this obvious way only works in two's complement, since the cast is defined
- as finding the congruence, which is only equivalent to bit chopping under two's
- complement. I have some code that _depends_ on this behavior, and is restricted
- to machines that have two's complement arithmetic and eight bit bytes/32 bit
- longs. But then again, the code emulates a microprocessor that uses two's
- complement arithmetic, so it's a biased example! :)
-
- Don't tell me that two's complement doesn't have its neat and useful aspects!
- It's a great idea that has been used successfully in many microprocessors! Of
- course, those microprocessors also give you overflow checks when you program
- them at the low level, that much is true.
- --
-
-